<?php
/**
 * [DB模型]
 * 
 * @version $Id: Account.php 277 2012-04-24 08:37:00Z linsir123 $
 */
class dbAccount extends ActiveRelation  
{
	/**
	 * @var 数据库表名
	 */
	public $table = 'account';
	
	/**
	 * 账户（收入,累加）
	 * // 场景：从淘宝API，取得交易记录时候
	 */
	public function in($uId, $money)
	{
		$money = floatval($money);
		$table = $this->getTable();
		$sql = "UPDATE `{$table}` SET `balance`=CAST(`balance`+{$money} AS DECIMAL(5,2)) WHERE uid={$uId}";
		return $this->execute($sql);
	}
	
	/**
	 * 账户（支出,减）
	 * // 场景：(管理员)支付用户的返现的时候
	 * // 同时修改账户状态
	 */
	public function out($uId, $money)
	{
		$money = floatval($money);
		$table = $this->getTable();
		$sql = "UPDATE `{$table}` SET `balance`=CAST(`balance`-{$money} AS DECIMAL(5,2)),`state`=0 WHERE uid={$uId}";
		return $this->execute($sql);
	}
}
